<?php
/**
 * Created by IntelliJ IDEA.
 * User: liuxin
 * Date: 2018/7/20
 * Time: 下午3:34
 */

namespace app\admin\controller;

use app\admin\controller\Base;
use app\admin\model\User;
use think\Controller;

class Login extends Controller
{
    //登陆
    public function index()
    {
        if ($this->request->isGet()) {
            if( session('user.id')){
                $this->redirect('@admin');
            }else{
                return $this->fetch('', ['title' => '用户登录']);
            }
            }

        $username = $this->request->post('username', '');
        $password = $this->request->post('password', '');
        $user = new User();
        $userInfo = $user->login($username, $password);
        if(!$userInfo){
            $this->error($user->getError());
        }else{
            $this->redirect('@admin');
        }
    }
    public function out(){
        session_start();
        session_destroy();

        $this->success('退出登陆成功','@admin/login');
    }

}
